//
//  RBLogisticsHeaderView.m
//  zhongzhenglu
//
//  Created by 马军凯 on 2023/5/9.
//

#import "RBLogisticsHeaderView.h"

@interface RBLogisticsHeaderView ()
//店铺名称
@property (weak, nonatomic) IBOutlet UILabel *storeNameLabel;
//图片
@property (weak, nonatomic) IBOutlet UIImageView *goodsImageView;
//名称
@property (weak, nonatomic) IBOutlet UILabel *goodsNameLabel;
//价格
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;
//物流公司
@property (weak, nonatomic) IBOutlet UILabel *companyNameLabel;
//物流单号
@property (weak, nonatomic) IBOutlet UILabel *numLabel;
//虚线
@property (weak, nonatomic) IBOutlet UIView *lineView;
//收货地址
@property (weak, nonatomic) IBOutlet UILabel *addressLabel;


@end

@implementation RBLogisticsHeaderView

- (void)awakeFromNib {
    [super awakeFromNib];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //
        CAShapeLayer *layer = CAShapeLayer.layer;
        [layer setBounds:self.lineView.bounds];
        [layer setPosition:CGPointMake(0.5, self.lineView.height / 2)];
        [layer setLineWidth:1];
        [layer setLineJoin:kCALineJoinRound];
        [layer setFillColor:[UIColor clearColor].CGColor];
        [layer setStrokeColor:[UIColor LC_hex:@"#518CFF"].CGColor];
        [layer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:1], nil]];
        
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 0.5, 0);
        CGPathAddLineToPoint(path, NULL, 0.5, self.lineView.height);
        [layer setPath:path];
        CGPathRelease(path);
        [self.lineView.layer addSublayer:layer];
    });
}
//赋值
- (void)setModel:(RBLogisticsModel *)model {
    _model = model;
    //店铺名称
    self.storeNameLabel.text = model.goods.store_name;
    //商品图片
    [self.goodsImageView setImageWithUrl:model.goods.file placeHolder:nil];
    //商品名称
    self.goodsNameLabel.text = model.goods.goods_name;
    //商品价格
    self.priceLabel.attributedText = [NSString changeSectionFontWithString:[NSString stringWithFormat:@"¥%@", model.goods.total_price] font:[UIFont systemFontOfSize:11] from:0 lenth:1];
    //物流公司
    self.companyNameLabel.text = model.kuaidi_desc.company_name;
    //物流单号
    self.numLabel.text = model.kuaidi.nu;
    //收货地址
    self.addressLabel.text = model.receive_addr;
}

//复制
- (IBAction)clickCopyBtn:(UIButton *)sender {
    UIPasteboard *board = UIPasteboard.generalPasteboard;
    board.string = self.numLabel.text;
    [JKToast showWithText:@"复制成功"];
}

@end
